﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MinhTam.DataAccess.Web;
using MinhTam.Objects;

public partial class Account_ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnChange_Click(object sender, EventArgs e)
    {
        string id = UserLogin.USER_ID(this);
        string sql = @"SELECT u.USERS_ID,u.USERS_PASS
        FROM USERS u WHERE u.USERS_ID='" + id + "'";
        bool ok = false;
        DataTable dt = SQLConnectWeb.GetTable(sql);
        if (dt != null && dt.Rows.Count > 0)
        {
            ok = dt.Rows[0][USERS.cl_USERS_PASS].ToString().Trim().Equals(HelpUtil.GetMD5(txtOldPass.Text));
        }
        if (ok)
        {
            string sqlU = string.Format("update USERS set USERS_PASS=N'{0}' where USERS_ID={1}", HelpUtil.GetMD5(txtNewPass.Text), id);
            if (SQLConnectWeb.ExecSQL(sqlU))
            {
                HelpControls.ShowMsgBox(this,"Đổi mật khẩu thành công!");
                Response.Redirect(HelpConstEnum.ADMIN_DEFAULT_PAGE);
            }
            else
                HelpControls.ShowMsgBox(this, "Đổi mật khẩu thất bại!");

        }
        else
        {
            errorPass.IsValid = false;

        }
    }

}
